import 'package:equatable/equatable.dart';
import 'package:mobile_app.core/core/domain/entities/access_credentials.dart';
import 'package:mobile_app.core/core/infrastructure/dtos/api/api_access_token_dto.dart';

const kApiAccessCredentialsAccessTokenDataKey = 'access_token';
const kApiAccessCredentialsRefreshTokenValueKey = 'refresh_token';

class ApiAccessCredentialsDto extends Equatable {
  const ApiAccessCredentialsDto._internal({
    required this.accessTokenDto,
    required this.refreshToken,
  });

  final ApiAccessTokenDto accessTokenDto;
  final String refreshToken;

  @override
  List<Object?> get props {
    return [
      accessTokenDto,
      refreshToken,
    ];
  }

  factory ApiAccessCredentialsDto.fromJson(Map<String, dynamic> json) {
    final accessTokenDto = ApiAccessTokenDto.fromJws(json[kApiAccessCredentialsAccessTokenDataKey]);

    return ApiAccessCredentialsDto._internal(
      accessTokenDto: accessTokenDto,
      refreshToken: json[kApiAccessCredentialsRefreshTokenValueKey],
    );
  }

  AccessCredentials toEntity() {
    return AccessCredentials(
      accessToken: accessTokenDto.toEntity(),
      refreshToken: refreshToken,
    );
  }
}
